/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// pscroll.hpp - Scroll bar class definitions.
//
// Author: Kenneth G. Maxwell
//
// Copyright (c) 1997-2000 Swell Software
//              All Rights Reserved.
//
// Unauthorized redistribution of this source code, in whole or part,
// without the express written permission of Swell Software
// is strictly prohibited.
//
// Notes:
//
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

#ifndef _PEGSCROLL_
#define _PEGSCROLL_


#define PSB_VERTICAL 1
#define PSB_HORIZONTAL 0

class PEG_WINDOW;

struct PegScrollInfo
{
    PEGINT Min;
    PEGINT Max;
    PEGINT Current;
    PEGINT Step;
    PEGINT Visible;
};



/*--------------------------------------------------------------------------*/
enum PegScrollBitmap {
    PBMI_SCROLL_FILL = 0,
    PBMI_SCROLL_UP,
    PBMI_SCROLL_DN,
    PBMI_THUMB_FILL,
    PBMI_THUMB_UP,
    PBMI_THUMB_DN
};

#define NUM_SCROLL_BITMAPS (PBMI_THUMB_DN + 1)
#define PCI_THUMB_COLOR     PCI_SELECTED

/*--------------------------------------------------------------------------*/
struct PegScrollDrawInfo
{
    PEGUINT BitmapIds[NUM_SCROLL_BITMAPS];
    PEGULONG Style;
    PEGSHORT MinOffset;
    PEGSHORT MaxOffset;
    PEGSHORT Width;
    PEGSHORT ThumbWidth;
};

/*--------------------------------------------------------------------------*/
class PegScrollThumb : public PegButton
{
    public:
        PegScrollThumb(PEGBOOL AmVertical, PEGULONG Style);
        virtual ~PegScrollThumb();

        virtual void Draw(const PegRect &Invalid);
        virtual PEGINT Message(const PegMessage &Mesg);

    protected:

        PEGBOOL MoveDraw(PEGINT Pos);

        PegRect mPosRect;
        PEGINT mLastMove;
        PEGINT mMoveStart;
        PEGBOOL mAmVertical;
        PEGBOOL mMoveMode;
};


/*--------------------------------------------------------------------------*/
class PegScroll : public PegThing
{
    public:
        PegScroll(PegScrollDrawInfo *pDrawInfo = NULL, PEGBOOL Vertical = TRUE);
        PegScroll(const PegRect &InRect, PegScrollInfo *si, PEGUSHORT Id = 0,
            PegScrollDrawInfo *pDrawInfo = NULL, PEGBOOL Vertical = TRUE);

        virtual ~PegScroll();

        PEGUINT GetBitmap(PEGUINT Index);

        PEGINT GetMinOffset() { return mDrawInfo.MinOffset; }
        PEGINT GetMaxOffset() { return mDrawInfo.MaxOffset; }
        PegScrollInfo *GetScrollInfo() {return &mScrollInfo;}
        virtual PEGINT Message(const PegMessage &Mesg);
        virtual void Reset();
        virtual void Reset(PegScrollInfo *);

        void SetBitmap(PEGUINT Index, PEGUINT BitmapId);

        void SetDrawInfo(PegScrollDrawInfo *pInfo, PEGBOOL Size = TRUE);
        void SetOffsets(PEGINT Top, PEGINT Bottom);

    protected:

        virtual void CheckScrollLimits(void);
        virtual void CreateButtons(void) {}
        virtual void ReadParentScrollInfo(void) = 0;
        virtual void SetThumbButtonPos(void) = 0;

        PegScrollThumb *mpThumbButton;
        PegScrollInfo mScrollInfo;
        PegScrollDrawInfo mDrawInfo;
};


/*--------------------------------------------------------------------------*/
class PegVScroll : public PegScroll
{
    public:

        PegVScroll(PegScrollDrawInfo *pDrawInfo = NULL);

        PegVScroll(const PegRect &InRect, PegScrollInfo *pSI, PEGUSHORT Id = 0,
            PegScrollDrawInfo *pDrawInfo = NULL);

        virtual ~PegVScroll();

        virtual void Draw(const PegRect &Invalid);
        virtual PEGINT Message(const PegMessage &Mesg);
        virtual void Resize(const PegRect &NewSize);

        enum MyButtonIds
        {
           IDB_UPBUTTON = 1000,
           IDB_DOWNBUTTON
        };

    protected:

        virtual void CreateButtons(void);
        virtual void ReadParentScrollInfo(void);
        virtual void SetThumbButtonPos(void);
};

/*--------------------------------------------------------------------------*/
class PegHScroll : public PegScroll
{
    public:

        PegHScroll(PegScrollDrawInfo *pDrawInfo = NULL);

        PegHScroll(const PegRect &InRect, PegScrollInfo *pSI, PEGUSHORT Id = 0,
            PegScrollDrawInfo *pDrawInfo = NULL);

        virtual ~PegHScroll();

        virtual void Draw(const PegRect &Invalid);
        virtual PEGINT Message(const PegMessage &Mesg);
        virtual void Resize(const PegRect &NewSize);

        enum MyButtonIds
        {
           IDB_LEFTBUTTON = 1000,
           IDB_RIGHTBUTTON
        };

    protected:

        virtual void CreateButtons(void);
        virtual void ReadParentScrollInfo(void);
        virtual void SetThumbButtonPos(void);
};

#endif

